<template>
	<view class="container">
		<jy-quick-btns></jy-quick-btns>
		<view class="questionbank">
			<!-- title -->
			<view class="questionbank-title">
				<view class="questionbank-title-item" v-for="(item, index) in questionBankList" :key="index">
					<view @click="questionBankChange(index)" :class="{btna:btnnum == index}">{{item}}</view>
					<text :class="{_underline: btnnum == index}"></text>
				</view>
			</view>
			<view id="nodata" v-if="nodata">
				<image src="../../../static/wudingdan.png" mode="aspectFit"></image>
			</view>
			
			<view class="questionbank-content">
				<!-- 我的考试-->
				<view class="myExam" :class="{dis:btnnum == 0}">
					<view class="item" v-for='item in over' :key='item.id'>
						<view class="left">
							<view class="title">{{ item.name }}</view>
							<view class="time">
								<view><image src="../../../static/shijian.png" mode=""></image><text>时长: {{ item.minute }}</text></view>
								<text class="score">成绩: {{ item.score == null? 0: item.score }}</text></view>
						</view>
						<view class="right">
							<button type="default" size="mini" @click="navigate(item.grade_id)" v-if="item.grade_id != null">查看考试</button>
							<button type="default" size="mini"  v-else>暂无成绩</button>
						</view>
					</view>
				</view>
			</view>
		</view>
		
		
	</view>
</template>

<script>
	import {checkUserinfo} from '@/request/checkUserinfo'
	export default {
		data() {
			return {
				questionBankList: ['我的考试'],
				btnnum: 0,
				getMyExamList:[],
				over:'',
				noStart:'',
				userinfo:{},
				shiti:{},
				nodata:false
			};
		},
		onShow() {
			checkUserinfo()
			let userinfo=uni.getStorageSync('userinfo')
			this.userinfo = userinfo.userdata
			if(userinfo.userdata){
				this.getMyExam()
			}
		},
		methods: {
			questionBankChange(e) {
				this.btnnum = e
			},
			navigate(id) {
				uni.navigateTo({
					url:'../examDetail/examDetail1?id='+id
				});
			},
			

			getMyExam(){
				const BASE_URL = uni.BASE_URL
				uni.request({
					url: BASE_URL+'index/exam1/getUserExamList',
					data:{
						page:0,
						uid:this.userinfo.id
					},
					method:'POST',
					success:(res) =>{
						console.log(res.data);
						if(res.data.code==0){
							this.getMyExamList = res.data.data
							this.over = res.data.data
							// this.over =  res.data.data.filter((val,index,arr)=>{
							// 	return val.exam_status == '已结束'
							// })
						}else{
							this.nodata=true
						}
					},
					fail:(res)=> {
						console.log(res.data);
					}
				});
			}
		}
	}
</script>

<style lang="less" scoped>
#nodata {
	width: 100%;
	height: 100vh;
	background-color: #fff;
	image {
		position: absolute;
		top: 50%;
		left: 50%;
		transform: translate(-50%, -70%);
	}
}
.questionbank {
	&-title{
		height: 125upx;
		background-color: #fff;
		padding-top: 45upx;
		box-sizing: border-box;
		display: flex;
		justify-content: space-around;
		&-item {
			flex: 1;
			display: flex;
			flex-direction: column;
			align-items: center;
			view {
			font-size: 30upx;
			color: #575757;
			}
			.btna { // 需要追加到view上的class
				font-weight: 700;
				color: #131313;
			}
			._underline { // 需要追加到view下方的下划线class
				width: 70upx;
				height: 7upx;
				background-color: #2f77ff;
				border-radius: 5upx;
				margin-top: 15upx;
			}
		}
		
	}
	
	&-content {
		.myExam {
			display: none;
			padding: 20upx;
			
			.item{
				box-sizing: border-box;
				width: 700upx;
				height: 200upx;
				background-color: white;
				border-radius: 10upx;
				display: flex;
				align-items: center;
				padding: 0 30upx;
				margin-bottom: 30upx;
				.left{
					box-sizing: border-box;
					width: 500upx;
					color: #333;
					font-size: 28upx;
					display: flex;
					flex-direction: column;
					.title{
						color: #000000;
					}
					.time{
						color: #8a8a8a;
						margin-top: 10upx;
						display: flex;
						image{
							width: 30upx;
							height: 30upx;
							margin-right: 10upx;
						}
					}
					.score{
						margin-left: 20upx;
						color: #8a8a8a;
					}
				}
				.right{
					width: 200upx;
					text-align: center;
					button{
						border-radius: 25upx;
						background-color: rgb(46,159,253);
						color: white;
						letter-spacing: 5upx;
					}
				}
			}
		}
		
		
		
		.noStart {
			display: none;
			padding: 20upx 30upx;
			.item{
				box-sizing: border-box;
				width: 700upx;
				height: 200upx;
				background-color: white;
				border-radius: 10upx;
				display: flex;
				margin-bottom: 30upx;
				.left{
					box-sizing: border-box;
					width: 450upx;
					height: 200upx;
					// background-color: pink;
					padding: 30upx;
					line-height: 54upx;
					color: #333;
					font-size: 28upx;
					.title{
						color: #000000;
					}
					image{
						width: 30upx;
						height: 30upx;
						margin-right: 10upx;
						line-height: 30upx;
					}
					.time{
						color: #8a8a8a;
						margin-top: 10upx;
					}
					.score{
						margin-left: 20upx;
						color: #8a8a8a;
					}
				}
				.right{
					width: 250upx;
					height: 200upx;
					// background-color: red;
					line-height: 230upx;
					text-align: center;
					button{
						border-radius: 25upx;
						background-color: rgb(46,159,253);
						color: white;
						letter-spacing: 5upx;
					}
				}
			}
		}
		
		.dis{
			display: block;
		}
	}
}


</style>
